home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / sh-utils.12 / sh-utils / sh-utils-1.12 / lib / getdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-05  |  47.8 KB  |  1,913 lines

  1.  
  2. /*  A Bison parser, made from ./getdate.y with Bison version GNU Bison version 1.22
  3.   */
  4.  
  5. #define YYBISON 1  /* Identify Bison output.  */
  6.  
  7. #define    tAGO    258
  8. #define    tDAY    259
  9. #define    tDAYZONE    260
  10. #define    tID    261
  11. #define    tMERIDIAN    262
  12. #define    tMINUTE_UNIT    263
  13. #define    tMONTH    264
  14. #define    tMONTH_UNIT    265
  15. #define    tSEC_UNIT    266
  16. #define    tSNUMBER    267
  17. #define    tUNUMBER    268
  18. #define    tZONE    269
  19. #define    tDST    270
  20.  
  21. #line 1 "./getdate.y"
  22.  
  23. /*
  24. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  25. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  26. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  27. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  28. **  send any email to Rich.
  29. **
  30. **  This grammar has 10 shift/reduce conflicts.
  31. **
  32. **  This code is in the public domain and has no copyright.
  33. */
  34. /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
  35. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. #include <config.h>
  39. #endif
  40.  
  41. /* Since the code of getdate.y is not included in the Emacs executable
  42.    itself, there is no need to #define static in this file.  Even if
  43.    the code were included in the Emacs executable, it probably
  44.    wouldn't do any harm to #undef it here; this will only cause
  45.    problems if we try to write to a static variable, which I don't
  46.    think this code needs to do.  */
  47. #ifdef emacs
  48. #undef static
  49. #endif
  50.  
  51. #include <stdio.h>
  52. #include <ctype.h>
  53.  
  54. /* The code at the top of get_date which figures out the offset of the
  55.    current time zone checks various CPP symbols to see if special
  56.    tricks are need, but defaults to using the gettimeofday system call.
  57.    Include <sys/time.h> if that will be used.  */
  58.  
  59. #if    defined (vms)
  60.  
  61. #include <types.h>
  62. #include <time.h>
  63.  
  64. #else
  65.  
  66. #include <sys/types.h>
  67.  
  68. #ifdef TIME_WITH_SYS_TIME
  69. #include <sys/time.h>
  70. #include <time.h>
  71. #else
  72. #ifdef HAVE_SYS_TIME_H
  73. #include <sys/time.h>
  74. #else
  75. #include <time.h>
  76. #endif
  77. #endif
  78.  
  79. #ifdef timezone
  80. #undef timezone /* needed for sgi */
  81. #endif
  82.  
  83. #if defined (HAVE_SYS_TIMEB_H)
  84. #include <sys/timeb.h>
  85. #else
  86. /*
  87. ** We use the obsolete `struct timeb' as part of our interface!
  88. ** Since the system doesn't have it, we define it here;
  89. ** our callers must do likewise.
  90. */
  91. struct timeb {
  92.     time_t        time;        /* Seconds since the epoch    */
  93.     unsigned short    millitm;    /* Field not used        */
  94.     short        timezone;    /* Minutes west of GMT        */
  95.     short        dstflag;    /* Field not used        */
  96. };
  97. #endif /* defined (HAVE_SYS_TIMEB_H) */
  98.  
  99. #endif    /* defined (vms) */
  100.  
  101. #if defined (STDC_HEADERS) || defined (USG)
  102. #include <string.h>
  103. #endif
  104.  
  105. /* Some old versions of bison generate parsers that use bcopy.
  106.    That loses on systems that don't provide the function, so we have
  107.    to redefine it here.  */
  108. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  109. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  110. #endif
  111.  
  112. extern struct tm    *gmtime ();
  113. extern struct tm    *localtime ();
  114.  
  115. #define yyparse getdate_yyparse
  116. #define yylex getdate_yylex
  117. #define yyerror getdate_yyerror
  118.  
  119. static int yylex ();
  120. static int yyerror ();
  121.  
  122. #define EPOCH        1970
  123. #define HOUR(x)        ((time_t)(x) * 60)
  124. #define SECSPERDAY    (24L * 60L * 60L)
  125.  
  126. #define MAX_BUFF_LEN    128   /* size of buffer to read the date into */
  127.  
  128. /*
  129. **  An entry in the lexical lookup table.
  130. */
  131. typedef struct _TABLE {
  132.     const char    *name;
  133.     int        type;
  134.     time_t    value;
  135. } TABLE;
  136.  
  137.  
  138. /*
  139. **  Daylight-savings mode:  on, off, or not yet known.
  140. */
  141. typedef enum _DSTMODE {
  142.     DSTon, DSToff, DSTmaybe
  143. } DSTMODE;
  144.  
  145. /*
  146. **  Meridian:  am, pm, or 24-hour style.
  147. */
  148. typedef enum _MERIDIAN {
  149.     MERam, MERpm, MER24
  150. } MERIDIAN;
  151.  
  152.  
  153. /*
  154. **  Global variables.  We could get rid of most of these by using a good
  155. **  union as the yacc stack.  (This routine was originally written before
  156. **  yacc had the %union construct.)  Maybe someday; right now we only use
  157. **  the %union very rarely.
  158. */
  159. static char    *yyInput;
  160. static DSTMODE    yyDSTmode;
  161. static time_t    yyDayOrdinal;
  162. static time_t    yyDayNumber;
  163. static int    yyHaveDate;
  164. static int    yyHaveDay;
  165. static int    yyHaveRel;
  166. static int    yyHaveTime;
  167. static int    yyHaveZone;
  168. static time_t    yyTimezone;
  169. static time_t    yyDay;
  170. static time_t    yyHour;
  171. static time_t    yyMinutes;
  172. static time_t    yyMonth;
  173. static time_t    yySeconds;
  174. static time_t    yyYear;
  175. static MERIDIAN    yyMeridian;
  176. static time_t    yyRelMonth;
  177. static time_t    yyRelSeconds;
  178.  
  179.  
  180. #line 160 "./getdate.y"
  181. typedef union {
  182.     time_t        Number;
  183.     enum _MERIDIAN    Meridian;
  184. } YYSTYPE;
  185.  
  186. #ifndef YYLTYPE
  187. typedef
  188.   struct yyltype
  189.     {
  190.       int timestamp;
  191.       int first_line;
  192.       int first_column;
  193.       int last_line;
  194.       int last_column;
  195.       char *text;
  196.    }
  197.   yyltype;
  198.  
  199. #define YYLTYPE yyltype
  200. #endif
  201.  
  202. #include <stdio.h>
  203.  
  204. #ifndef __cplusplus
  205. #ifndef __STDC__
  206. #define const
  207. #endif
  208. #endif
  209.  
  210.  
  211.  
  212. #define    YYFINAL        52
  213. #define    YYFLAG        -32768
  214. #define    YYNTBASE    19
  215.  
  216. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  217.  
  218. static const char yytranslate[] = {     0,
  219.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  220.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  221.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  225.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  226.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  227.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  228.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  229.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  230.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  232.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  233.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  234.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  235.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  236.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  237.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  238.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  239.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  240.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  241.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  242.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  243.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  244.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  245.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  246. };
  247.  
  248. #if YYDEBUG != 0
  249. static const short yyprhs[] = {     0,
  250.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  251.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  252.     62,    68,    72,    76,    79,    84,    87,    91,    94,    96,
  253.     99,   102,   104,   107,   110,   112,   115,   118,   120,   122,
  254.    123
  255. };
  256.  
  257. static const short yyrhs[] = {    -1,
  258.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  259.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  260.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  261.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  262.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  263.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  264.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  265.      0,    13,     9,    12,     0,     9,    13,     0,     9,    13,
  266.     17,    13,     0,    13,     9,     0,    13,     9,    13,     0,
  267.     26,     3,     0,    26,     0,    13,     8,     0,    12,     8,
  268.      0,     8,     0,    12,    11,     0,    13,    11,     0,    11,
  269.      0,    12,    10,     0,    13,    10,     0,    10,     0,    13,
  270.      0,     0,     7,     0
  271. };
  272.  
  273. #endif
  274.  
  275. #if YYDEBUG != 0
  276. static const short yyrline[] = { 0,
  277.    174,   175,   178,   181,   184,   187,   190,   193,   196,   202,
  278.    208,   215,   221,   231,   235,   239,   246,   250,   254,   260,
  279.    264,   269,   275,   281,   285,   290,   294,   301,   305,   308,
  280.    311,   314,   317,   320,   323,   326,   329,   332,   337,   364,
  281.    367
  282. };
  283.  
  284. static const char * const yytname[] = {   "$","error","$illegal.","tAGO","tDAY",
  285. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  286. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  287. "zone","day","date","rel","relunit","number","o_merid",""
  288. };
  289. #endif
  290.  
  291. static const short yyr1[] = {     0,
  292.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  293.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  294.     24,    24,    24,    24,    24,    24,    24,    25,    25,    26,
  295.     26,    26,    26,    26,    26,    26,    26,    26,    27,    28,
  296.     28
  297. };
  298.  
  299. static const short yyr2[] = {     0,
  300.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  301.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  302.      5,     3,     3,     2,     4,     2,     3,     2,     1,     2,
  303.      2,     1,     2,     2,     1,     2,     2,     1,     1,     0,
  304.      1
  305. };
  306.  
  307. static const short yydefact[] = {     1,
  308.      0,    17,    15,    32,     0,    38,    35,     0,    39,    14,
  309.      2,     3,     4,     6,     5,     7,    29,     8,    18,    24,
  310.     31,    36,    33,    19,     9,    30,    26,    37,    34,     0,
  311.      0,     0,    16,    28,     0,    23,    27,    22,    40,    20,
  312.     25,    41,    11,     0,    10,     0,    40,    21,    13,    12,
  313.      0,     0
  314. };
  315.  
  316. static const short yydefgoto[] = {     1,
  317.     11,    12,    13,    14,    15,    16,    17,    18,    45
  318. };
  319.  
  320. static const short yypact[] = {-32768,
  321.      0,    -1,-32768,-32768,     4,-32768,-32768,    25,    11,    -8,
  322. -32768,-32768,-32768,-32768,-32768,-32768,    21,-32768,-32768,     9,
  323. -32768,-32768,-32768,-32768,-32768,-32768,   -10,-32768,-32768,    16,
  324.     19,    24,-32768,-32768,    26,-32768,-32768,-32768,    18,    13,
  325. -32768,-32768,-32768,    27,-32768,    28,    -6,-32768,-32768,-32768,
  326.     38,-32768
  327. };
  328.  
  329. static const short yypgoto[] = {-32768,
  330. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  331. };
  332.  
  333.  
  334. #define    YYLAST        42
  335.  
  336.  
  337. static const short yytable[] = {    51,
  338.     42,    36,    37,     2,     3,    49,    33,     4,     5,     6,
  339.      7,     8,     9,    10,    24,    19,    20,    25,    26,    27,
  340.     28,    29,    30,    34,    42,    35,    31,    38,    32,    43,
  341.     46,    39,    21,    44,    22,    23,    40,    52,    41,    47,
  342.     48,    50
  343. };
  344.  
  345. static const short yycheck[] = {     0,
  346.      7,    12,    13,     4,     5,    12,    15,     8,     9,    10,
  347.     11,    12,    13,    14,     4,    17,    13,     7,     8,     9,
  348.     10,    11,    12,     3,     7,    17,    16,    12,    18,    12,
  349.     18,    13,     8,    16,    10,    11,    13,     0,    13,    13,
  350.     13,    47
  351. };
  352. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  353. #line 3 "/usr/local/lib/bison.simple"
  354.  
  355. /* Skeleton output parser for bison,
  356.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  357.  
  358.    This program is free software; you can redistribute it and/or modify
  359.    it under the terms of the GNU General Public License as published by
  360.    the Free Software Foundation; either version 1, or (at your option)
  361.    any later version.
  362.  
  363.    This program is distributed in the hope that it will be useful,
  364.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  365.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  366.    GNU General Public License for more details.
  367.  
  368.    You should have received a copy of the GNU General Public License
  369.    along with this program; if not, write to the Free Software
  370.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  371.  
  372.  
  373. #ifndef alloca
  374. #ifdef __GNUC__
  375. #define alloca __builtin_alloca
  376. #else /* not GNU C.  */
  377. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  378. #include <alloca.h>
  379. #else /* not sparc */
  380. #if defined (MSDOS) && !defined (__TURBOC__)
  381. #include <malloc.h>
  382. #else /* not MSDOS, or __TURBOC__ */
  383. #if defined(_AIX)
  384. #include <malloc.h>
  385.  #pragma alloca
  386. #else /* not MSDOS, __TURBOC__, or _AIX */
  387. #ifdef __hpux
  388. #ifdef __cplusplus
  389. extern "C" {
  390. void *alloca (unsigned int);
  391. };
  392. #else /* not __cplusplus */
  393. void *alloca ();
  394. #endif /* not __cplusplus */
  395. #endif /* __hpux */
  396. #endif /* not _AIX */
  397. #endif /* not MSDOS, or __TURBOC__ */
  398. #endif /* not sparc.  */
  399. #endif /* not GNU C.  */
  400. #endif /* alloca not defined.  */
  401.  
  402. /* This is the parser code that is written into each bison parser
  403.   when the %semantic_parser declaration is not specified in the grammar.
  404.   It was written by Richard Stallman by simplifying the hairy parser
  405.   used when %semantic_parser is specified.  */
  406.  
  407. /* Note: there must be only one dollar sign in this file.
  408.    It is replaced by the list of actions, each action
  409.    as one case of the switch.  */
  410.  
  411. #define yyerrok        (yyerrstatus = 0)
  412. #define yyclearin    (yychar = YYEMPTY)
  413. #define YYEMPTY        -2
  414. #define YYEOF        0
  415. #define YYACCEPT    return(0)
  416. #define YYABORT     return(1)
  417. #define YYERROR        goto yyerrlab1
  418. /* Like YYERROR except do call yyerror.
  419.    This remains here temporarily to ease the
  420.    transition to the new meaning of YYERROR, for GCC.
  421.    Once GCC version 2 has supplanted version 1, this can go.  */
  422. #define YYFAIL        goto yyerrlab
  423. #define YYRECOVERING()  (!!yyerrstatus)
  424. #define YYBACKUP(token, value) \
  425. do                                \
  426.   if (yychar == YYEMPTY && yylen == 1)                \
  427.     { yychar = (token), yylval = (value);            \
  428.       yychar1 = YYTRANSLATE (yychar);                \
  429.       YYPOPSTACK;                        \
  430.       goto yybackup;                        \
  431.     }                                \
  432.   else                                \
  433.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  434. while (0)
  435.  
  436. #define YYTERROR    1
  437. #define YYERRCODE    256
  438.  
  439. #ifndef YYPURE
  440. #define YYLEX        yylex()
  441. #endif
  442.  
  443. #ifdef YYPURE
  444. #ifdef YYLSP_NEEDED
  445. #define YYLEX        yylex(&yylval, &yylloc)
  446. #else
  447. #define YYLEX        yylex(&yylval)
  448. #endif
  449. #endif
  450.  
  451. /* If nonreentrant, generate the variables here */
  452.  
  453. #ifndef YYPURE
  454.  
  455. int    yychar;            /*  the lookahead symbol        */
  456. YYSTYPE    yylval;            /*  the semantic value of the        */
  457.                 /*  lookahead symbol            */
  458.  
  459. #ifdef YYLSP_NEEDED
  460. YYLTYPE yylloc;            /*  location data for the lookahead    */
  461.                 /*  symbol                */
  462. #endif
  463.  
  464. int yynerrs;            /*  number of parse errors so far       */
  465. #endif  /* not YYPURE */
  466.  
  467. #if YYDEBUG != 0
  468. int yydebug;            /*  nonzero means print parse trace    */
  469. /* Since this is uninitialized, it does not stop multiple parsers
  470.    from coexisting.  */
  471. #endif
  472.  
  473. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  474.  
  475. #ifndef    YYINITDEPTH
  476. #define YYINITDEPTH 200
  477. #endif
  478.  
  479. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  480.     (effective only if the built-in stack extension method is used).  */
  481.  
  482. #if YYMAXDEPTH == 0
  483. #undef YYMAXDEPTH
  484. #endif
  485.  
  486. #ifndef YYMAXDEPTH
  487. #define YYMAXDEPTH 10000
  488. #endif
  489.  
  490. /* Prevent warning if -Wstrict-prototypes.  */
  491. #ifdef __GNUC__
  492. int yyparse (void);
  493. #endif
  494.  
  495. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  496. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  497. #else                /* not GNU C or C++ */
  498. #ifndef __cplusplus
  499.  
  500. /* This is the most reliable way to avoid incompatibilities
  501.    in available built-in functions on various systems.  */
  502. static void
  503. __yy_bcopy (from, to, count)
  504.      char *from;
  505.      char *to;
  506.      int count;
  507. {
  508.   register char *f = from;
  509.   register char *t = to;
  510.   register int i = count;
  511.  
  512.   while (i-- > 0)
  513.     *t++ = *f++;
  514. }
  515.  
  516. #else /* __cplusplus */
  517.  
  518. /* This is the most reliable way to avoid incompatibilities
  519.    in available built-in functions on various systems.  */
  520. static void
  521. __yy_bcopy (char *from, char *to, int count)
  522. {
  523.   register char *f = from;
  524.   register char *t = to;
  525.   register int i = count;
  526.  
  527.   while (i-- > 0)
  528.     *t++ = *f++;
  529. }
  530.  
  531. #endif
  532. #endif
  533.  
  534. #line 184 "/usr/local/lib/bison.simple"
  535. int
  536. yyparse()
  537. {
  538.   register int yystate;
  539.   register int yyn;
  540.   register short *yyssp;
  541.   register YYSTYPE *yyvsp;
  542.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  543.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  544.  
  545.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  546.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  547.  
  548.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  549.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  550.  
  551. #ifdef YYLSP_NEEDED
  552.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  553.   YYLTYPE *yyls = yylsa;
  554.   YYLTYPE *yylsp;
  555.  
  556. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  557. #else
  558. #define YYPOPSTACK   (yyvsp--, yyssp--)
  559. #endif
  560.  
  561.   int yystacksize = YYINITDEPTH;
  562.  
  563. #ifdef YYPURE
  564.   int yychar;
  565.   YYSTYPE yylval;
  566.   int yynerrs;
  567. #ifdef YYLSP_NEEDED
  568.   YYLTYPE yylloc;
  569. #endif
  570. #endif
  571.  
  572.   YYSTYPE yyval;        /*  the variable used to return        */
  573.                 /*  semantic values from the action    */
  574.                 /*  routines                */
  575.  
  576.   int yylen;
  577.  
  578. #if YYDEBUG != 0
  579.   if (yydebug)
  580.     fprintf(stderr, "Starting parse\n");
  581. #endif
  582.  
  583.   yystate = 0;
  584.   yyerrstatus = 0;
  585.   yynerrs = 0;
  586.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  587.  
  588.   /* Initialize stack pointers.
  589.      Waste one element of value and location stack
  590.      so that they stay on the same level as the state stack.
  591.      The wasted elements are never initialized.  */
  592.  
  593.   yyssp = yyss - 1;
  594.   yyvsp = yyvs;
  595. #ifdef YYLSP_NEEDED
  596.   yylsp = yyls;
  597. #endif
  598.  
  599. /* Push a new state, which is found in  yystate  .  */
  600. /* In all cases, when you get here, the value and location stacks
  601.    have just been pushed. so pushing a state here evens the stacks.  */
  602. yynewstate:
  603.  
  604.   *++yyssp = yystate;
  605.  
  606.   if (yyssp >= yyss + yystacksize - 1)
  607.     {
  608.       /* Give user a chance to reallocate the stack */
  609.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  610.       YYSTYPE *yyvs1 = yyvs;
  611.       short *yyss1 = yyss;
  612. #ifdef YYLSP_NEEDED
  613.       YYLTYPE *yyls1 = yyls;
  614. #endif
  615.  
  616.       /* Get the current used size of the three stacks, in elements.  */
  617.       int size = yyssp - yyss + 1;
  618.  
  619. #ifdef yyoverflow
  620.       /* Each stack pointer address is followed by the size of
  621.      the data in use in that stack, in bytes.  */
  622. #ifdef YYLSP_NEEDED
  623.       /* This used to be a conditional around just the two extra args,
  624.      but that might be undefined if yyoverflow is a macro.  */
  625.       yyoverflow("parser stack overflow",
  626.          &yyss1, size * sizeof (*yyssp),
  627.          &yyvs1, size * sizeof (*yyvsp),
  628.          &yyls1, size * sizeof (*yylsp),
  629.          &yystacksize);
  630. #else
  631.       yyoverflow("parser stack overflow",
  632.          &yyss1, size * sizeof (*yyssp),
  633.          &yyvs1, size * sizeof (*yyvsp),
  634.          &yystacksize);
  635. #endif
  636.  
  637.       yyss = yyss1; yyvs = yyvs1;
  638. #ifdef YYLSP_NEEDED
  639.       yyls = yyls1;
  640. #endif
  641. #else /* no yyoverflow */
  642.       /* Extend the stack our own way.  */
  643.       if (yystacksize >= YYMAXDEPTH)
  644.     {
  645.       yyerror("parser stack overflow");
  646.       return 2;
  647.     }
  648.       yystacksize *= 2;
  649.       if (yystacksize > YYMAXDEPTH)
  650.     yystacksize = YYMAXDEPTH;
  651.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  652.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  653.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  654.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  655. #ifdef YYLSP_NEEDED
  656.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  657.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  658. #endif
  659. #endif /* no yyoverflow */
  660.  
  661.       yyssp = yyss + size - 1;
  662.       yyvsp = yyvs + size - 1;
  663. #ifdef YYLSP_NEEDED
  664.       yylsp = yyls + size - 1;
  665. #endif
  666.  
  667. #if YYDEBUG != 0
  668.       if (yydebug)
  669.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  670. #endif
  671.  
  672.       if (yyssp >= yyss + yystacksize - 1)
  673.     YYABORT;
  674.     }
  675.  
  676. #if YYDEBUG != 0
  677.   if (yydebug)
  678.     fprintf(stderr, "Entering state %d\n", yystate);
  679. #endif
  680.  
  681.   goto yybackup;
  682.  yybackup:
  683.  
  684. /* Do appropriate processing given the current state.  */
  685. /* Read a lookahead token if we need one and don't already have one.  */
  686. /* yyresume: */
  687.  
  688.   /* First try to decide what to do without reference to lookahead token.  */
  689.  
  690.   yyn = yypact[yystate];
  691.   if (yyn == YYFLAG)
  692.     goto yydefault;
  693.  
  694.   /* Not known => get a lookahead token if don't already have one.  */
  695.  
  696.   /* yychar is either YYEMPTY or YYEOF
  697.      or a valid token in external form.  */
  698.  
  699.   if (yychar == YYEMPTY)
  700.     {
  701. #if YYDEBUG != 0
  702.       if (yydebug)
  703.     fprintf(stderr, "Reading a token: ");
  704. #endif
  705.       yychar = YYLEX;
  706.     }
  707.  
  708.   /* Convert token to internal form (in yychar1) for indexing tables with */
  709.  
  710.   if (yychar <= 0)        /* This means end of input. */
  711.     {
  712.       yychar1 = 0;
  713.       yychar = YYEOF;        /* Don't call YYLEX any more */
  714.  
  715. #if YYDEBUG != 0
  716.       if (yydebug)
  717.     fprintf(stderr, "Now at end of input.\n");
  718. #endif
  719.     }
  720.   else
  721.     {
  722.       yychar1 = YYTRANSLATE(yychar);
  723.  
  724. #if YYDEBUG != 0
  725.       if (yydebug)
  726.     {
  727.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  728.       /* Give the individual parser a way to print the precise meaning
  729.          of a token, for further debugging info.  */
  730. #ifdef YYPRINT
  731.       YYPRINT (stderr, yychar, yylval);
  732. #endif
  733.       fprintf (stderr, ")\n");
  734.     }
  735. #endif
  736.     }
  737.  
  738.   yyn += yychar1;
  739.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  740.     goto yydefault;
  741.  
  742.   yyn = yytable[yyn];
  743.  
  744.   /* yyn is what to do for this token type in this state.
  745.      Negative => reduce, -yyn is rule number.
  746.      Positive => shift, yyn is new state.
  747.        New state is final state => don't bother to shift,
  748.        just return success.
  749.      0, or most negative number => error.  */
  750.  
  751.   if (yyn < 0)
  752.     {
  753.       if (yyn == YYFLAG)
  754.     goto yyerrlab;
  755.       yyn = -yyn;
  756.       goto yyreduce;
  757.     }
  758.   else if (yyn == 0)
  759.     goto yyerrlab;
  760.  
  761.   if (yyn == YYFINAL)
  762.     YYACCEPT;
  763.  
  764.   /* Shift the lookahead token.  */
  765.  
  766. #if YYDEBUG != 0
  767.   if (yydebug)
  768.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  769. #endif
  770.  
  771.   /* Discard the token being shifted unless it is eof.  */
  772.   if (yychar != YYEOF)
  773.     yychar = YYEMPTY;
  774.  
  775.   *++yyvsp = yylval;
  776. #ifdef YYLSP_NEEDED
  777.   *++yylsp = yylloc;
  778. #endif
  779.  
  780.   /* count tokens shifted since error; after three, turn off error status.  */
  781.   if (yyerrstatus) yyerrstatus--;
  782.  
  783.   yystate = yyn;
  784.   goto yynewstate;
  785.  
  786. /* Do the default action for the current state.  */
  787. yydefault:
  788.  
  789.   yyn = yydefact[yystate];
  790.   if (yyn == 0)
  791.     goto yyerrlab;
  792.  
  793. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  794. yyreduce:
  795.   yylen = yyr2[yyn];
  796.   if (yylen > 0)
  797.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  798.  
  799. #if YYDEBUG != 0
  800.   if (yydebug)
  801.     {
  802.       int i;
  803.  
  804.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  805.            yyn, yyrline[yyn]);
  806.  
  807.       /* Print the symbols being reduced, and their result.  */
  808.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  809.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  810.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  811.     }
  812. #endif
  813.  
  814.  
  815.   switch (yyn) {
  816.  
  817. case 3:
  818. #line 178 "./getdate.y"
  819. {
  820.         yyHaveTime++;
  821.     ;
  822.     break;}
  823. case 4:
  824. #line 181 "./getdate.y"
  825. {
  826.         yyHaveZone++;
  827.     ;
  828.     break;}
  829. case 5:
  830. #line 184 "./getdate.y"
  831. {
  832.         yyHaveDate++;
  833.     ;
  834.     break;}
  835. case 6:
  836. #line 187 "./getdate.y"
  837. {
  838.         yyHaveDay++;
  839.     ;
  840.     break;}
  841. case 7:
  842. #line 190 "./getdate.y"
  843. {
  844.         yyHaveRel++;
  845.     ;
  846.     break;}
  847. case 9:
  848. #line 196 "./getdate.y"
  849. {
  850.         yyHour = yyvsp[-1].Number;
  851.         yyMinutes = 0;
  852.         yySeconds = 0;
  853.         yyMeridian = yyvsp[0].Meridian;
  854.     ;
  855.     break;}
  856. case 10:
  857. #line 202 "./getdate.y"
  858. {
  859.         yyHour = yyvsp[-3].Number;
  860.         yyMinutes = yyvsp[-1].Number;
  861.         yySeconds = 0;
  862.         yyMeridian = yyvsp[0].Meridian;
  863.     ;
  864.     break;}
  865. case 11:
  866. #line 208 "./getdate.y"
  867. {
  868.         yyHour = yyvsp[-3].Number;
  869.         yyMinutes = yyvsp[-1].Number;
  870.         yyMeridian = MER24;
  871.         yyDSTmode = DSToff;
  872.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  873.     ;
  874.     break;}
  875. case 12:
  876. #line 215 "./getdate.y"
  877. {
  878.         yyHour = yyvsp[-5].Number;
  879.         yyMinutes = yyvsp[-3].Number;
  880.         yySeconds = yyvsp[-1].Number;
  881.         yyMeridian = yyvsp[0].Meridian;
  882.     ;
  883.     break;}
  884. case 13:
  885. #line 221 "./getdate.y"
  886. {
  887.         yyHour = yyvsp[-5].Number;
  888.         yyMinutes = yyvsp[-3].Number;
  889.         yySeconds = yyvsp[-1].Number;
  890.         yyMeridian = MER24;
  891.         yyDSTmode = DSToff;
  892.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  893.     ;
  894.     break;}
  895. case 14:
  896. #line 231 "./getdate.y"
  897. {
  898.         yyTimezone = yyvsp[0].Number;
  899.         yyDSTmode = DSToff;
  900.     ;
  901.     break;}
  902. case 15:
  903. #line 235 "./getdate.y"
  904. {
  905.         yyTimezone = yyvsp[0].Number;
  906.         yyDSTmode = DSTon;
  907.     ;
  908.     break;}
  909. case 16:
  910. #line 240 "./getdate.y"
  911. {
  912.         yyTimezone = yyvsp[-1].Number;
  913.         yyDSTmode = DSTon;
  914.     ;
  915.     break;}
  916. case 17:
  917. #line 246 "./getdate.y"
  918. {
  919.         yyDayOrdinal = 1;
  920.         yyDayNumber = yyvsp[0].Number;
  921.     ;
  922.     break;}
  923. case 18:
  924. #line 250 "./getdate.y"
  925. {
  926.         yyDayOrdinal = 1;
  927.         yyDayNumber = yyvsp[-1].Number;
  928.     ;
  929.     break;}
  930. case 19:
  931. #line 254 "./getdate.y"
  932. {
  933.         yyDayOrdinal = yyvsp[-1].Number;
  934.         yyDayNumber = yyvsp[0].Number;
  935.     ;
  936.     break;}
  937. case 20:
  938. #line 260 "./getdate.y"
  939. {
  940.         yyMonth = yyvsp[-2].Number;
  941.         yyDay = yyvsp[0].Number;
  942.     ;
  943.     break;}
  944. case 21:
  945. #line 264 "./getdate.y"
  946. {
  947.         yyMonth = yyvsp[-4].Number;
  948.         yyDay = yyvsp[-2].Number;
  949.         yyYear = yyvsp[0].Number;
  950.     ;
  951.     break;}
  952. case 22:
  953. #line 269 "./getdate.y"
  954. {
  955.         /* ISO 8601 format.  yyyy-mm-dd.  */
  956.         yyYear = yyvsp[-2].Number;
  957.         yyMonth = -yyvsp[-1].Number;
  958.         yyDay = -yyvsp[0].Number;
  959.     ;
  960.     break;}
  961. case 23:
  962. #line 275 "./getdate.y"
  963. {
  964.         /* e.g. 17-JUN-1992.  */
  965.         yyDay = yyvsp[-2].Number;
  966.         yyMonth = yyvsp[-1].Number;
  967.         yyYear = -yyvsp[0].Number;
  968.     ;
  969.     break;}
  970. case 24:
  971. #line 281 "./getdate.y"
  972. {
  973.         yyMonth = yyvsp[-1].Number;
  974.         yyDay = yyvsp[0].Number;
  975.     ;
  976.     break;}
  977. case 25:
  978. #line 285 "./getdate.y"
  979. {
  980.         yyMonth = yyvsp[-3].Number;
  981.         yyDay = yyvsp[-2].Number;
  982.         yyYear = yyvsp[0].Number;
  983.     ;
  984.     break;}
  985. case 26:
  986. #line 290 "./getdate.y"
  987. {
  988.         yyMonth = yyvsp[0].Number;
  989.         yyDay = yyvsp[-1].Number;
  990.     ;
  991.     break;}
  992. case 27:
  993. #line 294 "./getdate.y"
  994. {
  995.         yyMonth = yyvsp[-1].Number;
  996.         yyDay = yyvsp[-2].Number;
  997.         yyYear = yyvsp[0].Number;
  998.     ;
  999.     break;}
  1000. case 28:
  1001. #line 301 "./getdate.y"
  1002. {
  1003.         yyRelSeconds = -yyRelSeconds;
  1004.         yyRelMonth = -yyRelMonth;
  1005.     ;
  1006.     break;}
  1007. case 30:
  1008. #line 308 "./getdate.y"
  1009. {
  1010.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1011.     ;
  1012.     break;}
  1013. case 31:
  1014. #line 311 "./getdate.y"
  1015. {
  1016.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1017.     ;
  1018.     break;}
  1019. case 32:
  1020. #line 314 "./getdate.y"
  1021. {
  1022.         yyRelSeconds += yyvsp[0].Number * 60L;
  1023.     ;
  1024.     break;}
  1025. case 33:
  1026. #line 317 "./getdate.y"
  1027. {
  1028.         yyRelSeconds += yyvsp[-1].Number;
  1029.     ;
  1030.     break;}
  1031. case 34:
  1032. #line 320 "./getdate.y"
  1033. {
  1034.         yyRelSeconds += yyvsp[-1].Number;
  1035.     ;
  1036.     break;}
  1037. case 35:
  1038. #line 323 "./getdate.y"
  1039. {
  1040.         yyRelSeconds++;
  1041.     ;
  1042.     break;}
  1043. case 36:
  1044. #line 326 "./getdate.y"
  1045. {
  1046.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1047.     ;
  1048.     break;}
  1049. case 37:
  1050. #line 329 "./getdate.y"
  1051. {
  1052.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1053.     ;
  1054.     break;}
  1055. case 38:
  1056. #line 332 "./getdate.y"
  1057. {
  1058.         yyRelMonth += yyvsp[0].Number;
  1059.     ;
  1060.     break;}
  1061. case 39:
  1062. #line 337 "./getdate.y"
  1063. {
  1064.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1065.         yyYear = yyvsp[0].Number;
  1066.         else {
  1067.         if (yyvsp[0].Number>10000) {
  1068.             yyHaveDate++;
  1069.             yyDay= (yyvsp[0].Number)%100;
  1070.             yyMonth= (yyvsp[0].Number/100)%100;
  1071.             yyYear = yyvsp[0].Number/10000;
  1072.         }
  1073.         else {
  1074.             yyHaveTime++;
  1075.             if (yyvsp[0].Number < 100) {
  1076.             yyHour = yyvsp[0].Number;
  1077.             yyMinutes = 0;
  1078.             }
  1079.             else {
  1080.                 yyHour = yyvsp[0].Number / 100;
  1081.                 yyMinutes = yyvsp[0].Number % 100;
  1082.             }
  1083.             yySeconds = 0;
  1084.             yyMeridian = MER24;
  1085.             }
  1086.         }
  1087.     ;
  1088.     break;}
  1089. case 40:
  1090. #line 364 "./getdate.y"
  1091. {
  1092.         yyval.Meridian = MER24;
  1093.     ;
  1094.     break;}
  1095. case 41:
  1096. #line 367 "./getdate.y"
  1097. {
  1098.         yyval.Meridian = yyvsp[0].Meridian;
  1099.     ;
  1100.     break;}
  1101. }
  1102.    /* the action file gets copied in in place of this dollarsign */
  1103. #line 465 "/usr/local/lib/bison.simple"
  1104.  
  1105.   yyvsp -= yylen;
  1106.   yyssp -= yylen;
  1107. #ifdef YYLSP_NEEDED
  1108.   yylsp -= yylen;
  1109. #endif
  1110.  
  1111. #if YYDEBUG != 0
  1112.   if (yydebug)
  1113.     {
  1114.       short *ssp1 = yyss - 1;
  1115.       fprintf (stderr, "state stack now");
  1116.       while (ssp1 != yyssp)
  1117.     fprintf (stderr, " %d", *++ssp1);
  1118.       fprintf (stderr, "\n");
  1119.     }
  1120. #endif
  1121.  
  1122.   *++yyvsp = yyval;
  1123.  
  1124. #ifdef YYLSP_NEEDED
  1125.   yylsp++;
  1126.   if (yylen == 0)
  1127.     {
  1128.       yylsp->first_line = yylloc.first_line;
  1129.       yylsp->first_column = yylloc.first_column;
  1130.       yylsp->last_line = (yylsp-1)->last_line;
  1131.       yylsp->last_column = (yylsp-1)->last_column;
  1132.       yylsp->text = 0;
  1133.     }
  1134.   else
  1135.     {
  1136.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1137.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1138.     }
  1139. #endif
  1140.  
  1141.   /* Now "shift" the result of the reduction.
  1142.      Determine what state that goes to,
  1143.      based on the state we popped back to
  1144.      and the rule number reduced by.  */
  1145.  
  1146.   yyn = yyr1[yyn];
  1147.  
  1148.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1149.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1150.     yystate = yytable[yystate];
  1151.   else
  1152.     yystate = yydefgoto[yyn - YYNTBASE];
  1153.  
  1154.   goto yynewstate;
  1155.  
  1156. yyerrlab:   /* here on detecting error */
  1157.  
  1158.   if (! yyerrstatus)
  1159.     /* If not already recovering from an error, report this error.  */
  1160.     {
  1161.       ++yynerrs;
  1162.  
  1163. #ifdef YYERROR_VERBOSE
  1164.       yyn = yypact[yystate];
  1165.  
  1166.       if (yyn > YYFLAG && yyn < YYLAST)
  1167.     {
  1168.       int size = 0;
  1169.       char *msg;
  1170.       int x, count;
  1171.  
  1172.       count = 0;
  1173.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1174.       for (x = (yyn < 0 ? -yyn : 0);
  1175.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1176.         if (yycheck[x + yyn] == x)
  1177.           size += strlen(yytname[x]) + 15, count++;
  1178.       msg = (char *) malloc(size + 15);
  1179.       if (msg != 0)
  1180.         {
  1181.           strcpy(msg, "parse error");
  1182.  
  1183.           if (count < 5)
  1184.         {
  1185.           count = 0;
  1186.           for (x = (yyn < 0 ? -yyn : 0);
  1187.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1188.             if (yycheck[x + yyn] == x)
  1189.               {
  1190.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1191.             strcat(msg, yytname[x]);
  1192.             strcat(msg, "'");
  1193.             count++;
  1194.               }
  1195.         }
  1196.           yyerror(msg);
  1197.           free(msg);
  1198.         }
  1199.       else
  1200.         yyerror ("parse error; also virtual memory exceeded");
  1201.     }
  1202.       else
  1203. #endif /* YYERROR_VERBOSE */
  1204.     yyerror("parse error");
  1205.     }
  1206.  
  1207.   goto yyerrlab1;
  1208. yyerrlab1:   /* here on error raised explicitly by an action */
  1209.  
  1210.   if (yyerrstatus == 3)
  1211.     {
  1212.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1213.  
  1214.       /* return failure if at end of input */
  1215.       if (yychar == YYEOF)
  1216.     YYABORT;
  1217.  
  1218. #if YYDEBUG != 0
  1219.       if (yydebug)
  1220.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1221. #endif
  1222.  
  1223.       yychar = YYEMPTY;
  1224.     }
  1225.  
  1226.   /* Else will try to reuse lookahead token
  1227.      after shifting the error token.  */
  1228.  
  1229.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1230.  
  1231.   goto yyerrhandle;
  1232.  
  1233. yyerrdefault:  /* current state does not do anything special for the error token. */
  1234.  
  1235. #if 0
  1236.   /* This is wrong; only states that explicitly want error tokens
  1237.      should shift them.  */
  1238.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1239.   if (yyn) goto yydefault;
  1240. #endif
  1241.  
  1242. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1243.  
  1244.   if (yyssp == yyss) YYABORT;
  1245.   yyvsp--;
  1246.   yystate = *--yyssp;
  1247. #ifdef YYLSP_NEEDED
  1248.   yylsp--;
  1249. #endif
  1250.  
  1251. #if YYDEBUG != 0
  1252.   if (yydebug)
  1253.     {
  1254.       short *ssp1 = yyss - 1;
  1255.       fprintf (stderr, "Error: state stack now");
  1256.       while (ssp1 != yyssp)
  1257.     fprintf (stderr, " %d", *++ssp1);
  1258.       fprintf (stderr, "\n");
  1259.     }
  1260. #endif
  1261.  
  1262. yyerrhandle:
  1263.  
  1264.   yyn = yypact[yystate];
  1265.   if (yyn == YYFLAG)
  1266.     goto yyerrdefault;
  1267.  
  1268.   yyn += YYTERROR;
  1269.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1270.     goto yyerrdefault;
  1271.  
  1272.   yyn = yytable[yyn];
  1273.   if (yyn < 0)
  1274.     {
  1275.       if (yyn == YYFLAG)
  1276.     goto yyerrpop;
  1277.       yyn = -yyn;
  1278.       goto yyreduce;
  1279.     }
  1280.   else if (yyn == 0)
  1281.     goto yyerrpop;
  1282.  
  1283.   if (yyn == YYFINAL)
  1284.     YYACCEPT;
  1285.  
  1286. #if YYDEBUG != 0
  1287.   if (yydebug)
  1288.     fprintf(stderr, "Shifting error token, ");
  1289. #endif
  1290.  
  1291.   *++yyvsp = yylval;
  1292. #ifdef YYLSP_NEEDED
  1293.   *++yylsp = yylloc;
  1294. #endif
  1295.  
  1296.   yystate = yyn;
  1297.   goto yynewstate;
  1298. }
  1299. #line 372 "./getdate.y"
  1300.  
  1301.  
  1302. /* Month and day table. */
  1303. static TABLE const MonthDayTable[] = {
  1304.     { "january",    tMONTH,  1 },
  1305.     { "february",    tMONTH,  2 },
  1306.     { "march",        tMONTH,  3 },
  1307.     { "april",        tMONTH,  4 },
  1308.     { "may",        tMONTH,  5 },
  1309.     { "june",        tMONTH,  6 },
  1310.     { "july",        tMONTH,  7 },
  1311.     { "august",        tMONTH,  8 },
  1312.     { "september",    tMONTH,  9 },
  1313.     { "sept",        tMONTH,  9 },
  1314.     { "october",    tMONTH, 10 },
  1315.     { "november",    tMONTH, 11 },
  1316.     { "december",    tMONTH, 12 },
  1317.     { "sunday",        tDAY, 0 },
  1318.     { "monday",        tDAY, 1 },
  1319.     { "tuesday",    tDAY, 2 },
  1320.     { "tues",        tDAY, 2 },
  1321.     { "wednesday",    tDAY, 3 },
  1322.     { "wednes",        tDAY, 3 },
  1323.     { "thursday",    tDAY, 4 },
  1324.     { "thur",        tDAY, 4 },
  1325.     { "thurs",        tDAY, 4 },
  1326.     { "friday",        tDAY, 5 },
  1327.     { "saturday",    tDAY, 6 },
  1328.     { NULL }
  1329. };
  1330.  
  1331. /* Time units table. */
  1332. static TABLE const UnitsTable[] = {
  1333.     { "year",        tMONTH_UNIT,    12 },
  1334.     { "month",        tMONTH_UNIT,    1 },
  1335.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1336.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1337.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1338.     { "hour",        tMINUTE_UNIT,    60 },
  1339.     { "minute",        tMINUTE_UNIT,    1 },
  1340.     { "min",        tMINUTE_UNIT,    1 },
  1341.     { "second",        tSEC_UNIT,    1 },
  1342.     { "sec",        tSEC_UNIT,    1 },
  1343.     { NULL }
  1344. };
  1345.  
  1346. /* Assorted relative-time words. */
  1347. static TABLE const OtherTable[] = {
  1348.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1349.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1350.     { "today",        tMINUTE_UNIT,    0 },
  1351.     { "now",        tMINUTE_UNIT,    0 },
  1352.     { "last",        tUNUMBER,    -1 },
  1353.     { "this",        tMINUTE_UNIT,    0 },
  1354.     { "next",        tUNUMBER,    2 },
  1355.     { "first",        tUNUMBER,    1 },
  1356. /*  { "second",        tUNUMBER,    2 }, */
  1357.     { "third",        tUNUMBER,    3 },
  1358.     { "fourth",        tUNUMBER,    4 },
  1359.     { "fifth",        tUNUMBER,    5 },
  1360.     { "sixth",        tUNUMBER,    6 },
  1361.     { "seventh",    tUNUMBER,    7 },
  1362.     { "eighth",        tUNUMBER,    8 },
  1363.     { "ninth",        tUNUMBER,    9 },
  1364.     { "tenth",        tUNUMBER,    10 },
  1365.     { "eleventh",    tUNUMBER,    11 },
  1366.     { "twelfth",    tUNUMBER,    12 },
  1367.     { "ago",        tAGO,    1 },
  1368.     { NULL }
  1369. };
  1370.  
  1371. /* The timezone table. */
  1372. /* Some of these are commented out because a time_t can't store a float. */
  1373. static TABLE const TimezoneTable[] = {
  1374.     { "gmt",    tZONE,     HOUR ( 0) },    /* Greenwich Mean */
  1375.     { "ut",    tZONE,     HOUR ( 0) },    /* Universal (Coordinated) */
  1376.     { "utc",    tZONE,     HOUR ( 0) },
  1377.     { "wet",    tZONE,     HOUR ( 0) },    /* Western European */
  1378.     { "bst",    tDAYZONE,  HOUR ( 0) },    /* British Summer */
  1379.     { "wat",    tZONE,     HOUR ( 1) },    /* West Africa */
  1380.     { "at",    tZONE,     HOUR ( 2) },    /* Azores */
  1381. #if    0
  1382.     /* For completeness.  BST is also British Summer, and GST is
  1383.      * also Guam Standard. */
  1384.     { "bst",    tZONE,     HOUR ( 3) },    /* Brazil Standard */
  1385.     { "gst",    tZONE,     HOUR ( 3) },    /* Greenland Standard */
  1386. #endif
  1387. #if 0
  1388.     { "nft",    tZONE,     HOUR (3.5) },    /* Newfoundland */
  1389.     { "nst",    tZONE,     HOUR (3.5) },    /* Newfoundland Standard */
  1390.     { "ndt",    tDAYZONE,  HOUR (3.5) },    /* Newfoundland Daylight */
  1391. #endif
  1392.     { "ast",    tZONE,     HOUR ( 4) },    /* Atlantic Standard */
  1393.     { "adt",    tDAYZONE,  HOUR ( 4) },    /* Atlantic Daylight */
  1394.     { "est",    tZONE,     HOUR ( 5) },    /* Eastern Standard */
  1395.     { "edt",    tDAYZONE,  HOUR ( 5) },    /* Eastern Daylight */
  1396.     { "cst",    tZONE,     HOUR ( 6) },    /* Central Standard */
  1397.     { "cdt",    tDAYZONE,  HOUR ( 6) },    /* Central Daylight */
  1398.     { "mst",    tZONE,     HOUR ( 7) },    /* Mountain Standard */
  1399.     { "mdt",    tDAYZONE,  HOUR ( 7) },    /* Mountain Daylight */
  1400.     { "pst",    tZONE,     HOUR ( 8) },    /* Pacific Standard */
  1401.     { "pdt",    tDAYZONE,  HOUR ( 8) },    /* Pacific Daylight */
  1402.     { "yst",    tZONE,     HOUR ( 9) },    /* Yukon Standard */
  1403.     { "ydt",    tDAYZONE,  HOUR ( 9) },    /* Yukon Daylight */
  1404.     { "hst",    tZONE,     HOUR (10) },    /* Hawaii Standard */
  1405.     { "hdt",    tDAYZONE,  HOUR (10) },    /* Hawaii Daylight */
  1406.     { "cat",    tZONE,     HOUR (10) },    /* Central Alaska */
  1407.     { "ahst",    tZONE,     HOUR (10) },    /* Alaska-Hawaii Standard */
  1408.     { "nt",    tZONE,     HOUR (11) },    /* Nome */
  1409.     { "idlw",    tZONE,     HOUR (12) },    /* International Date Line West */
  1410.     { "cet",    tZONE,     -HOUR (1) },    /* Central European */
  1411.     { "met",    tZONE,     -HOUR (1) },    /* Middle European */
  1412.     { "mewt",    tZONE,     -HOUR (1) },    /* Middle European Winter */
  1413.     { "mest",    tDAYZONE,  -HOUR (1) },    /* Middle European Summer */
  1414.     { "mesz",    tDAYZONE,  -HOUR (1) },    /* Middle European Summer */
  1415.     { "swt",    tZONE,     -HOUR (1) },    /* Swedish Winter */
  1416.     { "sst",    tDAYZONE,  -HOUR (1) },    /* Swedish Summer */
  1417.     { "fwt",    tZONE,     -HOUR (1) },    /* French Winter */
  1418.     { "fst",    tDAYZONE,  -HOUR (1) },    /* French Summer */
  1419.     { "eet",    tZONE,     -HOUR (2) },    /* Eastern Europe, USSR Zone 1 */
  1420.     { "bt",    tZONE,     -HOUR (3) },    /* Baghdad, USSR Zone 2 */
  1421. #if 0
  1422.     { "it",    tZONE,     -HOUR (3.5) },/* Iran */
  1423. #endif
  1424.     { "zp4",    tZONE,     -HOUR (4) },    /* USSR Zone 3 */
  1425.     { "zp5",    tZONE,     -HOUR (5) },    /* USSR Zone 4 */
  1426. #if 0
  1427.     { "ist",    tZONE,     -HOUR (5.5) },/* Indian Standard */
  1428. #endif
  1429.     { "zp6",    tZONE,     -HOUR (6) },    /* USSR Zone 5 */
  1430. #if    0
  1431.     /* For completeness.  NST is also Newfoundland Standard, and SST is
  1432.      * also Swedish Summer. */
  1433.     { "nst",    tZONE,     -HOUR (6.5) },/* North Sumatra */
  1434.     { "sst",    tZONE,     -HOUR (7) },    /* South Sumatra, USSR Zone 6 */
  1435. #endif    /* 0 */
  1436.     { "wast",    tZONE,     -HOUR (7) },    /* West Australian Standard */
  1437.     { "wadt",    tDAYZONE,  -HOUR (7) },    /* West Australian Daylight */
  1438. #if 0
  1439.     { "jt",    tZONE,     -HOUR (7.5) },/* Java (3pm in Cronusland!) */
  1440. #endif
  1441.     { "cct",    tZONE,     -HOUR (8) },    /* China Coast, USSR Zone 7 */
  1442.     { "jst",    tZONE,     -HOUR (9) },    /* Japan Standard, USSR Zone 8 */
  1443. #if 0
  1444.     { "cast",    tZONE,     -HOUR (9.5) },/* Central Australian Standard */
  1445.     { "cadt",    tDAYZONE,  -HOUR (9.5) },/* Central Australian Daylight */
  1446. #endif
  1447.     { "east",    tZONE,     -HOUR (10) },    /* Eastern Australian Standard */
  1448.     { "eadt",    tDAYZONE,  -HOUR (10) },    /* Eastern Australian Daylight */
  1449.     { "gst",    tZONE,     -HOUR (10) },    /* Guam Standard, USSR Zone 9 */
  1450.     { "nzt",    tZONE,     -HOUR (12) },    /* New Zealand */
  1451.     { "nzst",    tZONE,     -HOUR (12) },    /* New Zealand Standard */
  1452.     { "nzdt",    tDAYZONE,  -HOUR (12) },    /* New Zealand Daylight */
  1453.     { "idle",    tZONE,     -HOUR (12) },    /* International Date Line East */
  1454.     {  NULL  }
  1455. };
  1456.  
  1457. /* Military timezone table. */
  1458. static TABLE const MilitaryTable[] = {
  1459.     { "a",    tZONE,    HOUR (  1) },
  1460.     { "b",    tZONE,    HOUR (  2) },
  1461.     { "c",    tZONE,    HOUR (  3) },
  1462.     { "d",    tZONE,    HOUR (  4) },
  1463.     { "e",    tZONE,    HOUR (  5) },
  1464.     { "f",    tZONE,    HOUR (  6) },
  1465.     { "g",    tZONE,    HOUR (  7) },
  1466.     { "h",    tZONE,    HOUR (  8) },
  1467.     { "i",    tZONE,    HOUR (  9) },
  1468.     { "k",    tZONE,    HOUR ( 10) },
  1469.     { "l",    tZONE,    HOUR ( 11) },
  1470.     { "m",    tZONE,    HOUR ( 12) },
  1471.     { "n",    tZONE,    HOUR (- 1) },
  1472.     { "o",    tZONE,    HOUR (- 2) },
  1473.     { "p",    tZONE,    HOUR (- 3) },
  1474.     { "q",    tZONE,    HOUR (- 4) },
  1475.     { "r",    tZONE,    HOUR (- 5) },
  1476.     { "s",    tZONE,    HOUR (- 6) },
  1477.     { "t",    tZONE,    HOUR (- 7) },
  1478.     { "u",    tZONE,    HOUR (- 8) },
  1479.     { "v",    tZONE,    HOUR (- 9) },
  1480.     { "w",    tZONE,    HOUR (-10) },
  1481.     { "x",    tZONE,    HOUR (-11) },
  1482.     { "y",    tZONE,    HOUR (-12) },
  1483.     { "z",    tZONE,    HOUR (  0) },
  1484.     { NULL }
  1485. };
  1486.  
  1487.  
  1488.  
  1489.  
  1490. /* ARGSUSED */
  1491. static int
  1492. yyerror (s)
  1493.     char    *s;
  1494. {
  1495.   return 0;
  1496. }
  1497.  
  1498.  
  1499. static time_t
  1500. ToSeconds (Hours, Minutes, Seconds, Meridian)
  1501.     time_t    Hours;
  1502.     time_t    Minutes;
  1503.     time_t    Seconds;
  1504.     MERIDIAN    Meridian;
  1505. {
  1506.   if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1507.     return -1;
  1508.   switch (Meridian) {
  1509.   case MER24:
  1510.     if (Hours < 0 || Hours > 23)
  1511.       return -1;
  1512.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1513.   case MERam:
  1514.     if (Hours < 1 || Hours > 12)
  1515.       return -1;
  1516.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1517.   case MERpm:
  1518.     if (Hours < 1 || Hours > 12)
  1519.       return -1;
  1520.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1521.   default:
  1522.     abort ();
  1523.   }
  1524.   /* NOTREACHED */
  1525. }
  1526.  
  1527.  
  1528. static time_t
  1529. Convert (Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1530.     time_t    Month;
  1531.     time_t    Day;
  1532.     time_t    Year;
  1533.     time_t    Hours;
  1534.     time_t    Minutes;
  1535.     time_t    Seconds;
  1536.     MERIDIAN    Meridian;
  1537.     DSTMODE    DSTmode;
  1538. {
  1539.   static int DaysInMonth[12] = {
  1540.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1541.   };
  1542.   time_t    tod;
  1543.   time_t    Julian;
  1544.   int        i;
  1545.  
  1546.   if (Year < 0)
  1547.     Year = -Year;
  1548.   if (Year < 100)
  1549.     Year += 1900;
  1550.   DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1551.     ? 29 : 28;
  1552.   if (Year < EPOCH || Year > 1999
  1553.       || Month < 1 || Month > 12
  1554.       /* Lint fluff:  "conversion from long may lose accuracy" */
  1555.       || Day < 1 || Day > DaysInMonth[(int)--Month])
  1556.     return -1;
  1557.  
  1558.   for (Julian = Day - 1, i = 0; i < Month; i++)
  1559.     Julian += DaysInMonth[i];
  1560.   for (i = EPOCH; i < Year; i++)
  1561.     Julian += 365 + (i % 4 == 0);
  1562.   Julian *= SECSPERDAY;
  1563.   Julian += yyTimezone * 60L;
  1564.   if ((tod = ToSeconds (Hours, Minutes, Seconds, Meridian)) < 0)
  1565.     return -1;
  1566.   Julian += tod;
  1567.   if (DSTmode == DSTon
  1568.       || (DSTmode == DSTmaybe && localtime (&Julian)->tm_isdst))
  1569.     Julian -= 60 * 60;
  1570.   return Julian;
  1571. }
  1572.  
  1573.  
  1574. static time_t
  1575. DSTcorrect (Start, Future)
  1576.     time_t    Start;
  1577.     time_t    Future;
  1578. {
  1579.   time_t    StartDay;
  1580.   time_t    FutureDay;
  1581.  
  1582.   StartDay = (localtime (&Start)->tm_hour + 1) % 24;
  1583.   FutureDay = (localtime (&Future)->tm_hour + 1) % 24;
  1584.   return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1585. }
  1586.  
  1587.  
  1588. static time_t
  1589. RelativeDate (Start, DayOrdinal, DayNumber)
  1590.     time_t    Start;
  1591.     time_t    DayOrdinal;
  1592.     time_t    DayNumber;
  1593. {
  1594.   struct tm    *tm;
  1595.   time_t    now;
  1596.  
  1597.   now = Start;
  1598.   tm = localtime (&now);
  1599.   now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1600.   now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1601.   return DSTcorrect (Start, now);
  1602. }
  1603.  
  1604.  
  1605. static time_t
  1606. RelativeMonth (Start, RelMonth)
  1607.     time_t    Start;
  1608.     time_t    RelMonth;
  1609. {
  1610.   struct tm    *tm;
  1611.   time_t    Month;
  1612.   time_t    Year;
  1613.  
  1614.   if (RelMonth == 0)
  1615.     return 0;
  1616.   tm = localtime (&Start);
  1617.   Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1618.   Year = Month / 12;
  1619.   Month = Month % 12 + 1;
  1620.   return DSTcorrect (Start,
  1621.              Convert (Month, (time_t)tm->tm_mday, Year,
  1622.                   (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1623.                   MER24, DSTmaybe));
  1624. }
  1625.  
  1626.  
  1627. static int
  1628. LookupWord (buff)
  1629.     char        *buff;
  1630. {
  1631.   register char    *p;
  1632.   register char    *q;
  1633.   register const TABLE    *tp;
  1634.   int            i;
  1635.   int            abbrev;
  1636.  
  1637.   /* Make it lowercase. */
  1638.   for (p = buff; *p; p++)
  1639.     if (isupper (*p))
  1640.       *p = tolower (*p);
  1641.  
  1642.   if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0) {
  1643.     yylval.Meridian = MERam;
  1644.     return tMERIDIAN;
  1645.   }
  1646.   if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0) {
  1647.     yylval.Meridian = MERpm;
  1648.     return tMERIDIAN;
  1649.   }
  1650.  
  1651.   /* See if we have an abbreviation for a month. */
  1652.   if (strlen (buff) == 3)
  1653.     abbrev = 1;
  1654.   else if (strlen (buff) == 4 && buff[3] == '.') {
  1655.     abbrev = 1;
  1656.     buff[3] = '\0';
  1657.   }
  1658.   else
  1659.     abbrev = 0;
  1660.  
  1661.   for (tp = MonthDayTable; tp->name; tp++) {
  1662.     if (abbrev) {
  1663.       if (strncmp (buff, tp->name, 3) == 0) {
  1664.     yylval.Number = tp->value;
  1665.     return tp->type;
  1666.       }
  1667.     }
  1668.     else if (strcmp (buff, tp->name) == 0) {
  1669.       yylval.Number = tp->value;
  1670.       return tp->type;
  1671.     }
  1672.   }
  1673.  
  1674.   for (tp = TimezoneTable; tp->name; tp++)
  1675.     if (strcmp (buff, tp->name) == 0) {
  1676.       yylval.Number = tp->value;
  1677.       return tp->type;
  1678.     }
  1679.  
  1680.   if (strcmp (buff, "dst") == 0) 
  1681.     return tDST;
  1682.  
  1683.   for (tp = UnitsTable; tp->name; tp++)
  1684.     if (strcmp (buff, tp->name) == 0) {
  1685.       yylval.Number = tp->value;
  1686.       return tp->type;
  1687.     }
  1688.  
  1689.   /* Strip off any plural and try the units table again. */
  1690.   i = strlen (buff) - 1;
  1691.   if (buff[i] == 's') {
  1692.     buff[i] = '\0';
  1693.     for (tp = UnitsTable; tp->name; tp++)
  1694.       if (strcmp (buff, tp->name) == 0) {
  1695.     yylval.Number = tp->value;
  1696.     return tp->type;
  1697.       }
  1698.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1699.   }
  1700.  
  1701.   for (tp = OtherTable; tp->name; tp++)
  1702.     if (strcmp (buff, tp->name) == 0) {
  1703.       yylval.Number = tp->value;
  1704.       return tp->type;
  1705.     }
  1706.  
  1707.   /* Military timezones. */
  1708.   if (buff[1] == '\0' && isalpha (*buff)) {
  1709.     for (tp = MilitaryTable; tp->name; tp++)
  1710.       if (strcmp (buff, tp->name) == 0) {
  1711.     yylval.Number = tp->value;
  1712.     return tp->type;
  1713.       }
  1714.   }
  1715.  
  1716.   /* Drop out any periods and try the timezone table again. */
  1717.   for (i = 0, p = q = buff; *q; q++)
  1718.     if (*q != '.')
  1719.       *p++ = *q;
  1720.     else
  1721.       i++;
  1722.   *p = '\0';
  1723.   if (i)
  1724.     for (tp = TimezoneTable; tp->name; tp++)
  1725.       if (strcmp (buff, tp->name) == 0) {
  1726.     yylval.Number = tp->value;
  1727.     return tp->type;
  1728.       }
  1729.  
  1730.   return tID;
  1731. }
  1732.  
  1733.  
  1734. static int
  1735. yylex ()
  1736. {
  1737.   register char    c;
  1738.   register char    *p;
  1739.   char        buff[20];
  1740.   int            Count;
  1741.   int            sign;
  1742.  
  1743.   for ( ; ; ) {
  1744.     while (isspace (*yyInput))
  1745.       yyInput++;
  1746.  
  1747.     if (isdigit (c = *yyInput) || c == '-' || c == '+') {
  1748.       if (c == '-' || c == '+') {
  1749.     sign = c == '-' ? -1 : 1;
  1750.     if (!isdigit (*++yyInput))
  1751.       /* skip the '-' sign */
  1752.       continue;
  1753.       }
  1754.       else
  1755.     sign = 0;
  1756.       for (yylval.Number = 0; isdigit (c = *yyInput++); )
  1757.     yylval.Number = 10 * yylval.Number + c - '0';
  1758.       yyInput--;
  1759.       if (sign < 0)
  1760.     yylval.Number = -yylval.Number;
  1761.       return sign ? tSNUMBER : tUNUMBER;
  1762.     }
  1763.     if (isalpha (c)) {
  1764.       for (p = buff; isalpha (c = *yyInput++) || c == '.'; )
  1765.     if (p < &buff[sizeof buff - 1])
  1766.       *p++ = c;
  1767.       *p = '\0';
  1768.       yyInput--;
  1769.       return LookupWord (buff);
  1770.     }
  1771.     if (c != '(')
  1772.       return *yyInput++;
  1773.     Count = 0;
  1774.     do {
  1775.       c = *yyInput++;
  1776.       if (c == '\0')
  1777.     return c;
  1778.       if (c == '(')
  1779.     Count++;
  1780.       else if (c == ')')
  1781.     Count--;
  1782.     } while (Count > 0);
  1783.   }
  1784. }
  1785.  
  1786. #define TM_YEAR_ORIGIN 1900
  1787.  
  1788. /* Yield A - B, measured in seconds.  */
  1789. static long
  1790. difftm (a, b)
  1791.      struct tm *a, *b;
  1792. {
  1793.   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
  1794.   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
  1795.   long days = (
  1796.            /* difference in day of year */
  1797.            a->tm_yday - b->tm_yday
  1798.            /* + intervening leap days */
  1799.            +  ((ay >> 2) - (by >> 2))
  1800.            -  (ay/100 - by/100)
  1801.            +  ((ay/100 >> 2) - (by/100 >> 2))
  1802.            /* + difference in years * 365 */
  1803.            +  (long)(ay-by) * 365
  1804.            );
  1805.   return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
  1806.           + (a->tm_min - b->tm_min))
  1807.       + (a->tm_sec - b->tm_sec));
  1808. }
  1809.  
  1810. time_t
  1811. get_date (p, now)
  1812.     char        *p;
  1813.     struct timeb    *now;
  1814. {
  1815.   struct tm        *tm, gmt;
  1816.   struct timeb    ftz;
  1817.   time_t        Start;
  1818.   time_t        tod;
  1819.  
  1820.   yyInput = p;
  1821.   if (now == NULL) {
  1822.     now = &ftz;
  1823.     (void)time (&ftz.time);
  1824.  
  1825.     if (! (tm = gmtime (&ftz.time)))
  1826.       return -1;
  1827.     gmt = *tm;            /* Make a copy, in case localtime modifies *tm.  */
  1828.  
  1829.     if (! (tm = localtime (&ftz.time)))
  1830.       return -1;
  1831.     
  1832.     ftz.timezone = difftm (&gmt, tm) / 60;
  1833.     if (tm->tm_isdst)
  1834.       ftz.timezone += 60;
  1835.   }
  1836.  
  1837.   tm = localtime (&now->time);
  1838.   yyYear = tm->tm_year;
  1839.   yyMonth = tm->tm_mon + 1;
  1840.   yyDay = tm->tm_mday;
  1841.   yyTimezone = now->timezone;
  1842.   yyDSTmode = DSTmaybe;
  1843.   yyHour = 0;
  1844.   yyMinutes = 0;
  1845.   yySeconds = 0;
  1846.   yyMeridian = MER24;
  1847.   yyRelSeconds = 0;
  1848.   yyRelMonth = 0;
  1849.   yyHaveDate = 0;
  1850.   yyHaveDay = 0;
  1851.   yyHaveRel = 0;
  1852.   yyHaveTime = 0;
  1853.   yyHaveZone = 0;
  1854.  
  1855.   if (yyparse ()
  1856.       || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1857.     return -1;
  1858.  
  1859.   if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1860.     Start = Convert (yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1861.              yyMeridian, yyDSTmode);
  1862.     if (Start < 0)
  1863.       return -1;
  1864.   }
  1865.   else {
  1866.     Start = now->time;
  1867.     if (!yyHaveRel)
  1868.       Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1869.   }
  1870.  
  1871.   Start += yyRelSeconds;
  1872.   Start += RelativeMonth (Start, yyRelMonth);
  1873.  
  1874.   if (yyHaveDay && !yyHaveDate) {
  1875.     tod = RelativeDate (Start, yyDayOrdinal, yyDayNumber);
  1876.     Start += tod;
  1877.   }
  1878.  
  1879.   /* Have to do *something* with a legitimate -1 so it's distinguishable
  1880.    * from the error return value.  (Alternately could set errno on error.) */
  1881.   return Start == -1 ? 0 : Start;
  1882. }
  1883.  
  1884.  
  1885. #if    defined (TEST)
  1886.  
  1887. /* ARGSUSED */
  1888. int
  1889. main (ac, av)
  1890.     int        ac;
  1891.     char    *av[];
  1892. {
  1893.   char buff[MAX_BUFF_LEN + 1];
  1894.   time_t d;
  1895.  
  1896.   (void)printf ("Enter date, or blank line to exit.\n\t> ");
  1897.   (void)fflush (stdout);
  1898.  
  1899.   buff[MAX_BUFF_LEN] = 0;
  1900.   while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0]) {
  1901.     d = get_date (buff, (struct timeb *)NULL);
  1902.     if (d == -1)
  1903.       (void)printf ("Bad format - couldn't convert.\n");
  1904.     else
  1905.       (void)printf ("%s", ctime (&d));
  1906.     (void)printf ("\t> ");
  1907.     (void)fflush (stdout);
  1908.   }
  1909.   exit (0);
  1910.   /* NOTREACHED */
  1911. }
  1912. #endif    /* defined (TEST) */
  1913.